#include<stdio.h>
#include "../include/vfs.h"
#include<stdlib.h>
#include<string.h>

int initialize_vfs()
{
	FILE *fp,*test;
	Header *header;
	FD *fd;
	char input[50];
	int in,i,j=0;
	long inp;
	
	fp = fopen(filesystem_name,"r+b");

	test = fopen("../src/initializevfs.txt","r");

	header=malloc(sizeof(Header));
	fread(header,sizeof(Header),1,fp);
	
	fd = malloc(sizeof(FD));
	
	i = fscanf(test,"%s",input);
	strcpy(fd->filename,input);

	i = fscanf(test,"%s",input);
	strcpy(fd->path,input);

	i = fscanf(test,"%d",&in);
	fd->file_type = in;

	i = fscanf(test,"%ld",&inp);
	fd->file_size = inp;

	i = fscanf(test,"%ld",&inp);
	fd->block_no = inp;

		strcpy(header->fd_list[j].filename,fd->filename);
		strcpy(header->fd_list[j].path,fd->path);
		header->fd_list[j].file_type = fd->file_type;
		header->fd_list[j].file_size=fd->file_size;
		header->fd_list[j].block_no=fd->block_no;
		header->used_FD++;
	
	rewind(fp);
	fwrite(header,sizeof(Header),1,fp);

	fclose(fp);



	return 0;
}

